<template>
	<view class="chidai_list">
		<div class="tabs">
			<div class="item" @click='tabSwicth(index)' v-for="(item,index) in tabs" :key='index'>
				<div :class="['name',currentTab==index && 'active']">{{item.name}}</div>
			</div>
		</div>
		<!--  -->
		<div class="detail_info" v-if="currentTab===0">
			  <uv-parse :content="change(info.content)"></uv-parse>
		</div>
		<div class="list_box" v-if="currentTab===1">
			<div class="item" @click='toDetail(item.id)' v-for="(item,index) in data.list" :key="index">
				<image class="pic"  :src="baseURL+item.image" mode=""></image>
				<div class="desc">{{item.title}}</div>
			</div>
		</div>
	</view>
</template>

<script>
	import { getBingInfo,getnewList } from '@/network/api.js'
	import { baseURL } from '@/network/config.js'
	export default {
		data() {
			return {
				currentTab:0,
				tabs:[{name:"老年痴呆症介绍"},{name:"健康资讯"}],
				info:{content:''},
				data:{
					total:0,
					list:[]
				},
				baseURL
			}
		},
		onLoad(options){
			const { id,title} = options
			uni.setNavigationBarTitle({
				title
			});

			this.tabs[0].name = title
			this.getBing(id)
			this.getList(id)
		},
		methods: {
			tabSwicth(index){
				this.currentTab = index
			},
			navTo(path){uni.navigateTo({url: path});},
			async getBing(id){
				const {data} = await getBingInfo({id})
				console.log('info:',data)
				this.info = data || {content:'没有信息'}
			},
			async getList(bingId){
				const { data } = await getnewList({bingId})
				console.log(data)
				this.data = data
			},
			toDetail(id){
				uni.navigateTo({
					url:`/pages/chidai_detail/chidai_detail?id=${id}`
				})
			},
			change(strValue) {
			      strValue = strValue.replace(/&amp;/g, "&");
			      strValue = strValue.replace(/&lt;/g, "<");
			      strValue = strValue.replace(/&gt;/g, ">");
			      strValue = strValue.replace(/&quot;/g, "\"");
			      strValue = strValue.replace(/&#39;/g, "'");
			      console.log(strValue,'2');
			      return strValue;
			    }
		}
	}
</script>

<style lang="less">
.chidai_list{
	padding:10rpx 25rpx;
}
.tabs{
	display: flex;
	align-items: center;
	height: 60rpx;
	.item{
		flex:1;
		display: flex;
		justify-content: center;
		align-items: center;
		.name{
			font-size: 28rpx;
			font-weight: 400;
			color: #828282;
			position: relative;
			padding: 0 5rpx;
		}
	}
	.active{
		&::before{
			content: '';
			position: absolute;
			right: 0;
			left: 0;
			bottom:-10rpx;
			height: 5rpx;
			background: #4E6FD9;
			border-radius: 2rpx;
		}
		&.name{
			color:#4E6FD9;
		}
	}
}
.detail_info{
	border-top:1px solid #EAEAEA;
	margin-top: 20rpx;
	padding-top: 39rpx;
}
	.list_box{
		border-top:1px solid #EAEAEA;
		margin-top: 20rpx;
		.item{
			display: flex;
			padding: 33rpx 0;
			border-bottom:1px solid #EAEAEA;
			&:last-child{
				border:none;
			}
			.pic{
				width: 340rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.desc{
				font-size: 28rpx;
				font-weight: 400;
				color: #444444;
				line-height: 50rpx;
				flex:1;
				margin: 18rpx 0 0 25rpx;
			}
		}
	}
</style>
